home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar / 1998 / Nov / di9811gd / Example3 / DllCode.pas < prev    next >
Pascal/Delphi Source File  |  1998-03-10  |  1KB  |  69 lines

  1. unit DllCode;
  2.  
  3. interface
  4.  
  5. uses Windows, Dialogs, SysUtils, Forms;
  6.  
  7. type
  8.   TTestObject = class(TObject)
  9.   public
  10.     ObjectName: String;
  11.     constructor Create;
  12.   end;
  13.  
  14. procedure DllShowMessage(Msg: String);
  15.  
  16. threadvar
  17.   tlObject: TTestObject;
  18.  
  19. const
  20.   MessageBoxTitle = 'Dll3';
  21.   CRLF = #13 + #10;
  22.  
  23. implementation
  24.  
  25. procedure DllShowMessage(Msg: String);
  26. begin
  27.   MessageBox(GetDesktopWindow, PChar(Msg), MessageBoxTitle,
  28.              MB_OK or MB_SETFOREGROUND or MB_TASKMODAL);
  29. end;
  30.  
  31. { TTestObject }
  32. constructor TTestObject.Create;
  33. begin
  34.   ObjectName := 'Test Object: ' + IntToStr(GetCurrentThreadID);
  35. end;
  36.  
  37. procedure DllEntry(Reason: Integer);
  38. begin
  39.   case Reason of
  40.     DLL_THREAD_ATTACH: begin
  41.       tlObject := TTestObject.Create;
  42.       DllShowMessage(tlObject.ObjectName);
  43.     end;
  44.     DLL_THREAD_DETACH: begin
  45.       if (tlObject = nil) then
  46.         DllShowMessage('Object is nil.')
  47.       else
  48.         DllShowMessage(tlObject.ObjectName);
  49.       tlObject.Free;
  50.     end;
  51.   end;
  52. end;
  53.  
  54. initialization
  55.  
  56.   IsMultiThread := True;
  57.   DllProc := @DllEntry;
  58.   tlObject := TTestObject.Create;
  59.  
  60. finalization
  61.  
  62.   if (tlObject = nil) then
  63.     DllShowMessage('Object is nil.')
  64.   else
  65.     DllShowMessage(tlObject.ObjectName);
  66.   tlObject.Free;
  67.  
  68. end.
  69.